package com.sgb.knowledgeshare.viewmodel;

import androidx.lifecycle.ViewModel;

import com.sgb.knowledgeshare.ShareConfig;
import com.sgb.knowledgeshare.entity.ShareDictEntity3;
import com.sgb.knowledgeshare.view.activity.ShareLandActivity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.VideoBean;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by：PC0033 on 2020/9/28 17:51
 */
public class ShareLandModel extends ViewModel {
    ShareLandActivity sharelandactivity;
    private ArrayList<Long> delectList;
    public void setActivity(ShareLandActivity shareLandActivity) {
        sharelandactivity = shareLandActivity;
    }
    //获取视频详情
    public void getPlayUrl(String videoId) {
        Map map = new HashMap();
        map.put("videoId",videoId);
        DialogHelper.showProgressDialog(sharelandactivity, null, "加载数据...", 0, true, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getPlayUrl(map).enqueue(new ICallBack<BaseEntity<VideoBean>>() {
            @Override
            public void onSuccess(BaseEntity<VideoBean> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    sharelandactivity.setPlayUrl(data.getData());
                } else {
                    MToast.showToast(sharelandactivity.getActivity(), data.getMsg());
                }
            }
        });
    }

    public void setLike(String s) {
        Map map = new HashMap();
        map.put("videoId", s);//longitude
        ShareConfig.getInstance().getApi().getlike(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {

            }
        });
    }

    public void deleteMyVideo(int id) {
        delectList = new ArrayList<>();
        delectList.add((long) id);
        DialogHelper.showProgressDialog(sharelandactivity, null, "删除中...", 0, true, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getDeleteMyVideo(delectList).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    MToast.showToast(sharelandactivity, "删除视频成功！");
                } else {
                    MToast.showToast(sharelandactivity, data.getMsg());
                }
            }
        });
    }

    //获取评论数量
    public void getCommentNum(VideoBean videoData) {
        Map map = new HashMap();
        map.put("videoId", videoData.getVideoId());//longitude
        ShareConfig.getInstance().getApi().getCommentCount(map).enqueue(new ICallBack<BaseEntity<ShareDictEntity3>>() {
            @Override
            public void onSuccess(BaseEntity<ShareDictEntity3> data) {
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    videoData.setCommentCount(Integer.parseInt(data.getData().getParam()));
                    sharelandactivity.setCommentNum(videoData);
                }
            }
        });
    }

    public void getplayVideo(String videoId) {
        Map map = new HashMap();
        map.put("videoId",videoId );
        ShareConfig.getInstance().getApi().getplayVideos(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {

            }
        });
    }


}
